#include "logarithmic.h"

double data2[MARK_SAMPLES];
double approx2[MARK_SPEC_HALF_SAMPLES], detail2[MARK_SPEC_HALF_SAMPLES];

void hideBit(double *spectrum, const unsigned short aBit) {
    int i = 0;
    float sign = 1;
    float elevator;
    float to_add = 0;
    unsigned short bit;

    if (aBit <= 0) bit = 0;
    else bit = 1;
    to_add = ((float) bit) * LOG_DELTA / 2.0;
    for (i = 0; i < MARK_SPEC_SAMPLES_PER_BIT; i++) {
        if (spectrum[i] < 0) sign = -1;
        else sign = 1;
        elevator = fabs(spectrum[i]);
        elevator *= LOG_SCALE;
        elevator = log10(elevator);
        elevator /= LOG_DELTA;
        elevator = (int) elevator;
        elevator *= LOG_DELTA;
        elevator += to_add;
        elevator = ((float) pow(10.00, elevator));
        elevator /= LOG_SCALE;
        spectrum[i] = sign * elevator;
    }
}

void getHidenBit(const double *spectrum, unsigned short * bit) {
    int i = 0;
    int zeroCount = 0, oneCount = 0;
    float rounded, common, result;
    for (i = 0; i < MARK_SPEC_SAMPLES_PER_BIT; i++) {
        common = fabs(spectrum[i]);
        common *= LOG_SCALE;
        common = log10(common);
        common *= LOG_DELTA;
        rounded = (int) (common + 0.5);
        common = fabs(common);
        result = fabs(common - rounded);
        if (result < 0.250)
            zeroCount++;
        else
            oneCount++;
    }

    if (zeroCount > oneCount)
        *bit = 0;
    else
        *bit = 1;
}